package com.yanqu.road.server.cmd.activity.jiuzhou;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.jiuzhou.JiuZhouProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.jiuzhou.CrossJiuZhouMgr;
import com.yanqu.road.server.manager.activity.jiuzhou.activity.CrossJiuZhouActivity;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = CrossProtocol.C_JIU_ZHOU_GET_OUT_ROUND_DATA,desc = "九州棋局向跨服获取淘汰赛数据")
public class CrossJiuZhouGetOutRoundCmd extends CrossCommand {

    private int activityId;

    private int roundId;

    private long userId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        JiuZhouProto.JiuZhouGetOutRoundRoomDataReqMsg reqMsg = JiuZhouProto.JiuZhouGetOutRoundRoomDataReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        roundId = reqMsg.getRoundId();
        userId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossJiuZhouActivity activity = CrossJiuZhouMgr.getActivity(activityId);
        if (activity == null) {
            ret = GameErrorCode.E_JIU_ZHOU_ACTIVITY_NOT_EXIST;
            return;
        }
        ret = activity.getOutRoundRoomData(roundId, userId);
    }

    @Override
    public void sendData() {
        if (ret != 0){
            JiuZhouProto.JiuZhouGetOutRoundRoomDataRespMsg.Builder builder = JiuZhouProto.JiuZhouGetOutRoundRoomDataRespMsg.newBuilder();
            builder.setRet(ret);
            MessageHelper.sendPacket(serverId, userId, YanQuMessageUtils.buildMessage(ClientProtocol.U_JIU_ZHOU_GET_OUT_ROUND_ROOMS, builder));
        }
    }
}
